local H = require "packages.ol_hegemony.util"

local zhiman = fk.CreateSkill{
    name = "new_ld__zhiman",
}

zhiman:addEffect(fk.DetermineDamageCaused,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(zhiman.name) and data.to ~= player
      end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,{
            skill_name = zhiman.name,
            prompt = "#ld__zhiman-invoke::"..data.to.id,
        })
      end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = data.to
        data:preventDamage()
        if #to:getCardIds{Player.Equip, Player.Judge} > 0 then
            local card = room:askToChooseCard(player,{
                target = to,
                flag = "ej",
                skill_name = zhiman.name,
            })
        room:obtainCard(player, card, true, fk.ReasonPrey)
        end
        if H.compareKingdomWith(to, player) and player:getMark("@@new_ld__zhiman_transform") == 0 and room:askToChoice(player,{choices = {"ld__zhiman_transform::" .. to.id, "Cancel"}, skill_name = zhiman.name,}) ~= "Cancel"
        and room:askToChoice(to, {choices = {"transform_deputy", "Cancel"}, skill_name = zhiman.name}) ~= "Cancel" then
            room:setPlayerMark(player, "@@new_ld__zhiman_transform", 1)
            H.transformGeneral(to, false, 3, false)
        end
        return true
      end
})

Fk:loadTranslationTable{
    ["new_ld__zhiman"] = "制蛮",
    [":new_ld__zhiman"] = "当你对其他角色造成伤害时，你可防止此伤害，你获得其装备区或判定区里的一张牌。若其与你势力相同，你可令其选择是否<a href='heg_transform_general'>变更副将</a>。",
    ["@@new_ld__zhiman_transform"] = "制蛮 已变更",

    ["$new_ld__zhiman1"] = "兵法谙熟于心，取胜千里之外！",
    ["$new_ld__zhiman2"] = "丞相多虑，且看我的！",
}

return zhiman